<template>
  <div class="card">
    <div class="left">
      <p class="present">员工当前状态</p>
      <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
        <el-form-item label="员工状态" size="small">
          <el-select v-model="ruleForm.workStatus" placeholder="请选择">
            <el-option
              v-for="(item, index) in statusOptions"
              :key="index"
              :label="item.statusName"
              :value="item.statusCode"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div class="right">
      <p class="time">工作时段配置</p>
      <el-time-picker
        is-range
        v-model="ruleForm.worktime"
        range-separator="-"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
        placeholder="选择时间范围"
        disabled
      >
      </el-time-picker>
    </div>
  </div>
</template>

<script>
import moment from "moment";
export default {
  props: {
    staffBasicVo1: {
      required: false
    }
  },
  data() {
    return {
      ruleForm: {
        workStatus: "0",
        worktime: [
          new Date("2021-8-30 8:00:00"),
          new Date("2021-8-30 21:00:00")
        ]
      },
      statusOptions: []
    };
  },
  methods: {
    async fetchStaffStatus() {
      await this.$http({
        url: "/staffadmin/homeService/staffManager/fetchStaffStatus",
        method: "get"
      }).then(res => {
        this.statusOptions = res;
      });
    },
    sendMsg() {
      this.$emit("save", {
        workStartHours: moment(this.ruleForm.worktime[0]).format("HH:mm:ss"),
        workEndHours: moment(this.ruleForm.worktime[1]).format("HH:mm:ss"),
        workStatus: this.ruleForm.workStatus
      });
    },
    initData() {
      // 编辑回显页面
      if (this.$route.query.staffCode) {
        this.ruleForm.workStatus = this.staffBasicVo1.workStatus;
      }
    }
  },
  mounted() {
    this.fetchStaffStatus();
    this.sendMsg();
  },
  watch: {
    ruleForm: {
      handler() {
        this.sendMsg();
      },
      deep: true
    },
    staffBasicVo1(newvalue) {
      if (newvalue) {
        this.initData();
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.card {
  background-color: #fff;
  display: flex;
  .left {
    border-right: 10px solid #ebeef1;
    .present {
      font-size: 18px;
      font-weight: 900;
      padding-left: 20px;
      height: 60px;
      line-height: 60px;
    }
    /deep/ .el-form {
      .el-form-item {
        margin-left: 20px;
        .el-select {
          width: 150px;
        }
      }
    }
  }
  .right {
    margin-left: 20px;
    .time {
      font-size: 18px;
      font-weight: 900;
      height: 60px;
      line-height: 60px;
    }
    /deep/ .el-date-editor {
      height: 30px;
      .el-input__icon {
        line-height: 24px;
      }
      .el-range-separator {
        line-height: 22px;
      }
    }
  }
}
</style>
